package com.kiln.juxingqs.adapter

import android.content.Context
import android.content.Intent
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import client.global.commlib.base.BaseLoadmoreAdapter
import client.global.commlib.base.BindingViewHoder
import client.global.commlib.toast.toast
import com.kiln.juxingqs.R
import com.kiln.juxingqs.api.bean.GoodsOrder
import com.kiln.juxingqs.api.bean.WdthRet
import com.kiln.juxingqs.databinding.LayoutWdthitemBinding
import com.kiln.juxingqs.dialog.LookWlDialog
import com.kiln.juxingqs.ui.WlDetailActivity

class WdthAdapter : BaseLoadmoreAdapter<WdthRet.Deliver> {


    constructor(context: Context) : super(context) {
    }

    override fun createVh(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {

        return BindingViewHoder(
            DataBindingUtil.inflate(
                layoutInflater,
                R.layout.layout_wdthitem,
                parent,
                false
            )
        )
    }

    override fun bindVh(holder: RecyclerView.ViewHolder, position: Int) {
        val bindingViewHolder = holder as BindingViewHoder<ViewDataBinding>
        val binding = bindingViewHolder.binding as LayoutWdthitemBinding
        binding.event = this
        val bean = getItem(position)
//        binding.tvWl.isEnabled = false
//        binding.tvWl.setTextColor(context.resources.getColor(R.color.gold_false))
        when (bean.status) {
            0 -> {
                binding.status = "未发货"
            }
            1 -> { //确认收货
                binding.status = "已发货"
//                binding.tvWl.isEnabled = true
//                binding.tvWl.setTextColor(context.resources.getColor(R.color.gold_color))
            }
            2->{
                binding.status = "已收货"
            }
        }
        binding.bean = bean
    }

    fun lookWl(bean: WdthRet.Deliver) {
        if (bean.logistics_num.isNullOrEmpty() || bean.logistics_name.isNullOrEmpty()) {
            toast("暂无信息")
            return
        }
//        LookWlDialog(context).apply {
//            dh = bean.logistics_num
//            gs = bean.logistics_name
//        }.show()
        context.startActivity(Intent(context, WlDetailActivity::class.java).apply {
            putExtra("orderId", "${bean.id}")
//            putExtra("bean", bean)
        })
    }

    var shuohuo: ((b: WdthRet.Deliver) -> Unit)? = null

    fun shouHuo(b: WdthRet.Deliver) {
        shuohuo?.invoke(b)
    }


}